package com.huizhonglm.diap.presenters.wallet;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.CommonResponse;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.Status;
import com.huizhonglm.diap.api.model.wallet.BankCardAddParams;
import com.huizhonglm.diap.ui.wallet.iView.BankCardAddIView;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2015-07-07 11:19
 */
public class BankCardAddPresenter {

    private BankCardAddIView iView;

    public BankCardAddPresenter(BankCardAddIView iView) {
        this.iView = iView;
    }

    public void addBankCard(BankCardAddParams params) {
        API.http().post("addBankCard", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    CommonResponse resp = JSON.parseObject(result, CommonResponse.class);
                    if (resp != null && Status.SUCCESS.equals(resp.getStatus())){
                        iView.addBankCardSuccess();
                    } else {
                        iView.addBankCardFailure();
                    }
                } else {
                    iView.addBankCardFailure();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.addBankCardFailure();
            }
        });
    }
}
